(function () {
    "use strict";

    angular.module('core').factory('contaContabilService', factory);
    factory.$inject = ['$http', '$q'];

    function factory($http, $q) {

        return {
            get: function (id) {
                var deferred = $q.defer();
                $http.post('/contaContabil/get', id)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            getAll: function (args) {
                var deferred = $q.defer();
                $http.post('/contaContabil/getall', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            count: function (args) {
                var deferred = $q.defer();
                $http.post('/contaContabil/count', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },

            /* verifique a MovimentacaoConta no aquivo movimentacao-conta.js */

            prepareNew: function () {
                var deferred = $q.defer();
                $http.post('/contaContabil/prepareNew')
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            prepare: function (item) {
                var deferred = $q.defer();
                $http.post('/contaContabil/prepare', item)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            prepareNewSubconta: function (item) {
                var deferred = $q.defer();
                $http.post('/contaContabil/prepareNewSubconta', item)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },

            save: function (item) {
                var deferred = $q.defer();
                $http.post('/contaContabil/save', item)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            delete: function (id) {
                var args = { id: id };
                var deferred = $q.defer();
                $http.post('/contaContabil/delete', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
        };
    }

})();


